import { http } from "@/utils/http";
import httpConfig from "@/utils/http/httpConfig";
const prefix = httpConfig.system + "/tool/";
/**
 * 获取数据源列表
 * @param params
 * @returns
 */
export function datasourceList(params: any) {
  return http.get(prefix + "gen/datasource/list", { params });
}
/**
 * 获取数据员响应
 * @param params
 * @returns
 */
export function getDatasourceInfo(params: any) {
  return http.get(prefix + "gen/datasource/" + params);
}

/**
 * 新增 数据源
 * @param params
 * @returns
 */
export function addDataSource(params: any) {
  return http.post(prefix + "gen/datasource", { params });
}

/**
 * 修改数据源
 * @param params
 * @returns
 */
export function editDataSource(params: any) {
  return http.post(prefix + "gen/datasource/edit", { data: params });
}
/**
 * 删除数据源
 * @param params
 * @returns
 */
export function delDataSource(params: any) {
  return http.post(prefix + "gen/datasource/del", { data: params });
}

// 代码生成已选数据表列表接口
export function generateTable(params: any) {
  return http.get(prefix + "gen/list", { params });
}

/**
 * 查询指定数据源的表
 * @param params
 * @returns
 */
export function dataTable(params: any) {
  return http.post(prefix + "gen/db/list", { data: params });
}

// 数据表所有列表接口
export function dataTableAll() {
  return http.get(httpConfig.system + "/gen/dbAll", {});
}

//表名查字段
export function dataTableToColumn(params: any) {
  return http.get(httpConfig.system + "/gen/dbColumn", { params });
}
/**
 * 选择要生成代码的数据表
 * 已经同步表结构了
 * @param params  {storeId:"",tables:"xx,xxx"}
 * @returns
 */
export function selectTable(params: any) {
  return http.post(prefix + "gen/importTable", { params });
}

// 已选择的数据表详情
export function tableDetail(params: any) {
  return http.get(prefix + "gen/" + params.id);
}

/**
 * 删除已选择的数据表
 * @param params  [id]
 * @returns
 */
export function generateDelete(params: any) {
  return http.post(prefix + "gen/delGenCode", { data: params });
}

//编辑已选表字段
export function generateEdit(params: any) {
  return http.post(prefix + "gen/edit", { data: params });
}

/**
 * 预览代码
 * @param params  tableId
 * @returns
 */
export function generatePreview(params: any) {
  return http.get(prefix + "gen/preview/" + params);
}

//生成代码
export function generateCode(params: any) {
  return http.get(prefix + "gen/genCode/" + params, { data: params });
}

/**
 * 下载代码
 * @param params tableName
 * @returns
 */
export function downloadCode(params: any) {
  return http.get(
    prefix + "gen/download/" + params,
    {},
    {
      responseType: "blob"
    }
  );
}

/**
 * 下载代码 批量
 * @param params  '表1,表2'
 * @returns
 */
export function batchGenCode(params: any) {
  return http.get(
    prefix + "gen/batchGenCode/" + params,
    {},
    {
      responseType: "blob"
    }
  );
}
